package com.newly.common.base.entity.sys.auth.entity.bo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.newly.common.base.constants.AuthConstant;
import com.newly.common.base.entity.business.Po.Company;
import com.newly.common.base.entity.business.Po.Site;
import com.newly.common.base.entity.device.po.DevicePo;
import com.newly.common.base.entity.sys.domain.po.DomainPo;
import com.newly.common.base.entity.sys.menu.po.MenuPo;
import com.newly.common.base.entity.sys.tenant.po.TenantPo;
import lombok.Data;

import java.util.List;

/**
 * @program: newly-parent
 * @remark: 权限实体
 * @author: guan
 * @create: 2022-01-13 18:56
 */
@Data
public class AuthEntityBo {

    private String code;

    private String name;

    private String remark;

    private List<EntityData> entityDatum;


    public AuthEntityBo() {
    }

    public AuthEntityBo(AuthConstant.AuthEntityType authEntityType, List<EntityData> entityDatum) {
        this.code = String.valueOf(authEntityType.getCode());
        this.name = authEntityType.getName();
        this.remark = authEntityType.getRemark();
        this.entityDatum = entityDatum;
    }

    @Data
    public static class EntityData {
        /**
         * 权限实体id
         */
        private String id;
        /**
         * 权限实体名称
         */
        private String name;
        /**
         * 子项
         */
        private List<EntityData> children;

        public EntityData(TenantPo tenantPo) {
            this.id = tenantPo.getId().toString();
            this.name = tenantPo.getUsername();
        }

        public EntityData() {
        }

        public EntityData(DomainPo domainPo) {
            this.id = domainPo.getId().toString();
            this.name = domainPo.getName();
        }

        public EntityData(MenuPo menuPo) {
            if (!ObjectUtil.isEmpty(menuPo)) {
                BeanUtil.copyProperties(menuPo, this);
            }
        }

        public EntityData(Company company) {
            this.id = company.getId().toString();
            this.name = company.getName();
        }

        public EntityData(Site site) {
            this.id = site.getId().toString();
            this.name = site.getName();
        }

        public EntityData(DevicePo devicePo) {
            this.id = devicePo.getId().toString();
            this.name = devicePo.getName();
        }
    }
}
